package com.androidx.p013lv.invention.activity;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.androidx.p013lv.base.bean.TopTabBean;
import com.androidx.p013lv.base.bean.TopTabListBean;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.invention.C1069R;
import com.androidx.p013lv.invention.adapter.AdapterTopTab;
import com.androidx.p013lv.invention.databinding.ActivityTopBinding;
import com.androidx.p013lv.invention.fragment.TopFragment;
import com.google.android.material.tabs.TabLayout;
import com.gyf.immersionbar.ImmersionBar;
import java.util.ArrayList;
import java.util.List;

/* renamed from: com.androidx.lv.invention.activity.TopActivity */
public class TopActivity extends BaseActivity<ActivityTopBinding> {
    String HTTP_TAG = "queryBoard";
    AdapterTopTab adapter;
    List<LazyFragment> fragmentList;
    public int type;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return C1069R.C1074layout.activity_top;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        getInfo();
        ((ActivityTopBinding) this.binding).tvBack.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.invention.activity.TopActivity.View$OnClickListenerC11101 */

            public void onClick(View view) {
                TopActivity.this.finish();
            }
        });
        ViewGroup.LayoutParams layoutParams = ((ActivityTopBinding) this.binding).rlHead.getLayoutParams();
        layoutParams.height = (UiUtils.getWindowWidth() * 214) / 420;
        ((ActivityTopBinding) this.binding).rlHead.setLayoutParams(layoutParams);
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        HttpUtils.getInsatance().get(UrlManager.getInsatance().queryBoard(), new HttpCallback<BaseRes<TopTabListBean>>(this.HTTP_TAG, this) {
            /* class com.androidx.p013lv.invention.activity.TopActivity.C11112 */

            public void onLvSuccess(BaseRes<TopTabListBean> baseRes) {
                if (baseRes.getCode() != 200) {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                } else if (baseRes.getData() == null || baseRes.getData().getList() == null || baseRes.getData().getList().size() <= 0) {
                    ToastUtils.getInstance().showWeak("沒有數據，請稍後再試");
                } else {
                    TopActivity.this.fragmentList = new ArrayList();
                    for (TopTabBean topTabBean : baseRes.getData().getList()) {
                        TopActivity.this.fragmentList.add(TopFragment.newInstance(topTabBean));
                    }
                    TopActivity topActivity = TopActivity.this;
                    topActivity.adapter = new AdapterTopTab(topActivity.fragmentList, baseRes.getData().getList(), TopActivity.this.getSupportFragmentManager(), 1);
                    ((ActivityTopBinding) TopActivity.this.binding).viewPager.setAdapter(TopActivity.this.adapter);
                    ((ActivityTopBinding) TopActivity.this.binding).tabLayout.addOnTabSelectedListener((TabLayout.OnTabSelectedListener) new TabLayout.OnTabSelectedListener() {
                        /* class com.androidx.p013lv.invention.activity.TopActivity.C11112.C11121 */

                        @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
                        public void onTabReselected(TabLayout.Tab tab) {
                        }

                        @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
                        public void onTabSelected(TabLayout.Tab tab) {
                            TopActivity.this.changeTabTextView(tab, true);
                        }

                        @Override // com.google.android.material.tabs.TabLayout.BaseOnTabSelectedListener
                        public void onTabUnselected(TabLayout.Tab tab) {
                            TopActivity.this.changeTabTextView(tab, false);
                        }
                    });
                    ((ActivityTopBinding) TopActivity.this.binding).tabLayout.setupWithViewPager(((ActivityTopBinding) TopActivity.this.binding).viewPager);
                    if (((ActivityTopBinding) TopActivity.this.binding).tabLayout.getTabCount() >= 2) {
                        for (int i = 1; i < ((ActivityTopBinding) TopActivity.this.binding).tabLayout.getTabCount(); i++) {
                            TopActivity topActivity2 = TopActivity.this;
                            topActivity2.changeTabTextView(((ActivityTopBinding) topActivity2.binding).tabLayout.getTabAt(i), false);
                        }
                    }
                    if (TopActivity.this.type != 0) {
                        for (int i2 = 0; i2 < baseRes.getData().getList().size(); i2++) {
                            if (TopActivity.this.type == baseRes.getData().getList().get(i2).getType()) {
                                ((ActivityTopBinding) TopActivity.this.binding).viewPager.setCurrentItem(i2);
                                return;
                            }
                        }
                    }
                }
            }
        });
    }

    public void changeTabTextView(TabLayout.Tab tab, boolean z) {
        if (tab.getCustomView() == null) {
            tab.setCustomView(C1069R.C1074layout.tab_layout_text);
        }
        TextView textView = (TextView) tab.getCustomView().findViewById(16908308);
        if (z) {
            textView.setTextAppearance(getActivity(), C1069R.C1076style.TabLayoutBoldTextSize);
        } else {
            textView.setTextAppearance(getActivity(), C1069R.C1076style.TabLayoutTopNormalTextSize);
        }
    }

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityTopBinding) this.binding).toolbar).init();
    }
}
